package br.affero.web.security;

import java.beans.EventHandler;

import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Observes;
import javax.faces.context.FacesContext;

import org.jboss.seam.security.events.PostLoggedOutEvent;
import org.jboss.solder.logging.Logger;

@RequestScoped
public class SecurityEventHandler {

	 private static final Logger logger = Logger.getLogger(EventHandler.class);
	 
	    public void handlePostLoggedOutEvent(@Observes final PostLoggedOutEvent event) {
	    	FacesContext facesContext = FacesContext.getCurrentInstance();
	        logger.debugv("PostLoggedOutEvent triggered by user: {0}", event.getUser().getId());

	        facesContext.getExternalContext().invalidateSession();
	        facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, "/login.xhtml");
	    }
}
